package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.cacheable.CacheKey;
import com.itheima.cacheable.Cacheable;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author W.J.Y
 */
@RestController
@RequestMapping("setMeal")
public class SetMealController {


    @Reference(version = "1.0.0")
    private SetMealService setMealService;

    /**
     * 查询所有检查套餐
     * @return  返回结果
     */
    @Cacheable(expire = 600)
    @PostMapping("getSetMeal")
    public Result getSetMeal(){
        //调用业务层查询所有套餐数据
        List<Setmeal> setMeals = setMealService.findAll();
        return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,setMeals);
    }

    /**
     * 根据检查套餐ID查询检查套餐详细信息
     * @param id    检查套餐ID
     * @return 返回结果
     */
    @Cacheable(expire = 600)
    @RequestMapping("findById")
    public Result findById(@CacheKey(key = "id") int id){
        Setmeal setmeal = setMealService.findById(id);
        return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
    }
}
